<?php

/*
Process Add Tile (admin_add_tiles.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$directoryName = "$rootPath/images/user_images/opg_$game";
if (!file_exists($directoryName)) { mkdir($directoryName, 0777); }

$directoryName2 = "$rootPath/images/user_images/opg_$game/tiles";
if (!file_exists($directoryName2)) { mkdir($directoryName2, 0777); }

if ($HTTP_POST_FILES['tileImage']['size'] >= 32000)
{
	die(header(error("admin_add_tiles.php?game=$game", "Your image must be under 32,000 bytes (or 32kb)")));
}

if (!eregi("image/", $HTTP_POST_FILES['tileImage']['type']))
{
	die(header(error("admin_add_tiles.php?game=$game", "You can only use .gif, .jpg, and .jpeg files for images. Please convert the image to one of these file types.")));
}

if (!$tile_name)
{
	die(header(error("admin_add_tiles.php?game=$game", "Please do not leave any information blank!")));
}

mysql_query("INSERT INTO tile_types (tile_name,game) VALUES ('$tile_name','$game')");

$insert_id = mysql_insert_id();
	
$file = $HTTP_POST_FILES['tileImage']['tmp_name'];
$dest = "$rootPath/images/user_images/opg_$game/tiles/tile_$insert_id.gif";

copy($file, "$dest");

header("Location: admin_add_tiles.php?game=$game&error=The+tile+$tile_name+has+been+added!");

?>
